package com.cn.wxwinnie.java.mythread.mythreadWithMultiFunctions;

/**
 * @author 潇湘暮雨 E-mail:wxwinnie@hotmail.com
 * 
 * @version 创建时间：2014年3月27日 下午11:30:37
 * 
 */
public class TargetObjectWithTwoFunctions {
	private int n = 8;

	private int getN() {
		return n;
	}

	private void setN(int nn) {
		this.n = nn;
	}

	private final static TargetObjectWithTwoFunctions to = new TargetObjectWithTwoFunctions();

	private TargetObjectWithTwoFunctions() {
	}

	public static TargetObjectWithTwoFunctions getInstance() {
		return to;
	}

	public synchronized int add() {// 放置到一个方法中来
		int n = getN();
		setN(++n);
		System.out.println("inc:" + n);
		return n;
	}

	public synchronized int sub() {// 放置到一个方法中来
		int n = getN();
		setN(++n);
		System.out.println("inc:" + n);
		return n;

	}

}
